//#include<bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
int dist[155][155];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, m;
	cin >> n >> m;
	for (int i = 0;i <= n;i++) {
		for (int j = 0;j <= n;j++) {
			if (i == j)
				dist[i][j] = 0;
			else
				dist[i][j] = dist[j][i] = -1;
		}
	}
	for (int i = 0;i < m;i++) {
		int u, v;
		cin >> u >> v;
		dist[u][v] = dist[v][u] = 1;
	}

	for (int i = 1;i <= n;i++) {
		for (int j = 1;j <= n;j++) {
			cout << dist[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;

	for (int i = 1;i <= n;i++) {
		for (int j = 1;j <= n;j++) {
			for (int k = 1;k <= n;k++) {
				if (j == k)
					continue;
				if (dist[j][i] > 0 && dist[i][k] > 0)
				{
					if (dist[j][k] == -1)
						dist[j][k] = 1;
					else
						dist[j][k]++;
				}
			}
		}
	}
	for (int i = 1;i <= n;i++) {
		for (int j = 1;j <= n;j++) {
			cout << dist[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}